package cn.car.carguanli.util;

public class LocationUtil {
    private static final double EARTH_RADIUS = 6371000; // 地球半径，单位米

    /**
     * 计算两个位置点之间的距离（米）
     */
    public static double calculateDistance(double lat1, double lon1, double lat2, double lon2) {
        double dLat = Math.toRadians(lat2 - lat1);
        double dLon = Math.toRadians(lon2 - lon1);
        
        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
                Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
                Math.sin(dLon / 2) * Math.sin(dLon / 2);
        
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        
        return EARTH_RADIUS * c;
    }

    /**
     * 计算速度（米/秒）
     */
    public static double calculateSpeed(double distance, long timeInMillis) {
        return distance / (timeInMillis / 1000.0);
    }
} 